<?php
// +----------------------------------------------------------------------
// | CLTPHP.Pro [首页控制器]
// +----------------------------------------------------------------------
// | Copyright (c) 2019-2029 https://www.cltphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://www.cltphp.com/detail-140.html )
// +----------------------------------------------------------------------
// | Author: chichu <1109305987@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\common\model\Commission;
use think\facade\App;
use think\facade\View;
use think\facade\Db;

class Index extends Base
{

    // 后台框架
    public function index()
    {
        $auth = new \Auth();
        $menus = $auth->getMenus();
        return view('', compact('menus'));
    }

    // 首页
    public function console()
    {
        $count1 = \app\common\model\Users::count();
        //客户终端类型统计
        $type = ['会员'];
        //客户终端数值
        $users = \app\common\model\Users::count();
        $terminal[] = ["name" => $type[0], "value" => $users];

        //新增用户统计表
        $startTime = time() - (6 * 24 * 60 * 60);
        $oneTime = 24 * 60 * 60;
        $xAxis = [];
        $series = [];
        for ($i = 0; $i <= 6; $i++) {
            $xAxis[$i] = date('Y-m-d', $startTime + ($i * $oneTime));
            $series[$i] = Db::name('users')
                ->whereDay('create_time', $xAxis[$i])
                ->count();
        }
        return view('', compact('count1', 'type', 'terminal', 'xAxis', 'series'));
    }

    // 清除缓存
    public function clear()
    {
        $path = App::getRootPath() . 'runtime' . DIRECTORY_SEPARATOR;
        if (deleteDir($path)) {
            $result['msg'] = '清除缓存成功!';
            $result['code'] = 0;
        } else {
            $result['msg'] = '清除缓存失败!';
            $result['code'] = 1;
        }
        $result['url'] = url('admin/login/index');
        return json($result);
    }
}
